package org.springblade.app.feign;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springblade.app.config.FeignInterceptor;
import org.springblade.app.constant.AppConstant;
import org.springblade.app.feign.entity.SubAppInfoEntity;
import org.springblade.app.feign.entity.SubAppMenuEntity;
import org.springblade.app.feign.vo.SubAppMenuVO;
import org.springblade.core.tool.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * @author zhangyr
 * @version 1.0
 * @date 2022-08-24 9:36
 * @description 子应用
 */
@FeignClient(
//	value = AppConstant.APPLICATION_APP_NAME,
	name = AppConstant.IOT_APP_NAME,
	url = "${built-in.iot-app}",
	fallback = ISubAppClientFallback.class,
	configuration = FeignInterceptor.class
)
public interface IIotAppClient {

	/**
	 * 新增应用
	 *
	 * @param appInfo 子应用信息
	 * @return
	 */
	@PostMapping("/shy/app/save")
	R<SubAppInfoEntity> save(@RequestBody SubAppInfoEntity appInfo);

	/**
	 * 删除-通过appId 代码自定义代号
	 */
	@PostMapping("/shy/app/removeByAppId")
	R removeByAppId(@RequestParam("appIds") String appIds);

	/**
	 * 设置应用管理员
	 *
	 * @param userId    用户id
	 * @param isManager 设置管理员，1设置，0取消
	 * @return
	 */
	@PostMapping("/shy/app/setAppManager")
	R setAppManager(@RequestParam("appId") String appId, @RequestParam("userId") Long userId, @RequestParam("isManager") Integer isManager);

	/**
	 * 转让应用
	 *
	 * @param userId 用户id
	 * @param appId  应用id
	 * @return
	 */
	@PostMapping("/shy/app/transferApp")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "转让应用", notes = "传入app_info")
	@Transactional
	R transferApp(@RequestParam("userId") Long userId, @RequestParam("appId") String appId);

	/**
	 * 新增应用成员 代码自定义代号
	 *
	 * @param appId    应用id
	 * @param linkType 关联类型，1用户，2部门
	 * @param userIds  用户id的集合
	 * @return
	 */
	@PostMapping("/shy/app/addUser")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增应用成员", notes = "传入app_user")
	R addUser(@RequestParam("appId") String appId, @RequestParam("linkType") Integer linkType, @RequestParam("userIds") String userIds);

	/**
	 * 删除应用成员 代码自定义代号
	 *
	 * @param userIds  用户id的集合
	 * @param linkType 关联类型，1用户，2部门
	 * @param appId    应用id
	 * @return
	 */
	@PostMapping("/shy/app/deleteUser")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "删除应用成员", notes = "传入app_user")
	public R deleteUser(@RequestParam("userIds") String userIds, @RequestParam("linkType") Integer linkType, @RequestParam("appId") String appId);

	/**
	 * 修改应用
	 *
	 * @param appInfo
	 * @return
	 */
	@PostMapping("/shy/app/update")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "修改应用", notes = "")
	public R update(@RequestBody SubAppInfoEntity appInfo);

	/**
	 * 修改通过appId
	 *
	 * @param appInfo
	 * @return
	 */
	@PostMapping("/shy/app/updateByAppId")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "修改通过appId", notes = "")
	public R updateByAppId(@RequestBody SubAppInfoEntity appInfo);



	/**
	 * 懒加载列表-管理菜单
	 */
	@GetMapping("/shy/app_menu/lazy-list-manage")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "code", value = "菜单编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "name", value = "菜单名称", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "appId", value = "应用id", paramType = "query", dataType = "string",required = true),
		@ApiImplicitParam(name = "isManage", value = "是否为管理菜单，1是，0否", paramType = "query", dataType = "int")
	})
	@ApiOperation(value = "懒加载列表-管理菜单", notes = "传入menu")
	public R<List<SubAppMenuVO>> lazyListManageMenu(@RequestParam(value = "parentId",required = false)Long parentId, @ApiIgnore @RequestParam Map<String, Object> menu);

	/**
	 * 菜单详情
	 */
	@GetMapping("/shy/app_menu/getById")
	@ApiOperation(value = "详情", notes = "传入menu")
	public R<SubAppMenuVO> getById(@RequestParam(value = "id")Long id);

	/**
	 * 新增或修改-菜单
	 */
	@PostMapping("/shy/app_menu/submit")
	@ApiOperation(value = "新增或修改", notes = "传入menu")
	public R submitMenu(@RequestBody SubAppMenuEntity menu);

	/**
	 * 删除
	 */
	@PostMapping("/shy/app_menu/remove")
	@ApiOperation(value = "删除", notes = "传入ids")
	public R removeMenu(@ApiParam(value = "主键集合", required = true) @RequestParam String ids);
}
